var iconUpload;
var bannerUpload;

$(function(){

	$("#icon_upload_button").swfupload(CTX,
		{	
        	button_width : 90,
        	button_height : 20,
        	button_text_left_padding : 20,
	        button_text_top_padding : 0.4,
	        button_text : "上传",
			upload_url : fileUploadUrl,
			progress_bar : $("#upload_progress ul"),
			file_dialog_complete_handler : function(countFile,countAddFile,countAllFile){
				//根据接口文档，定义所需 参数  
				var options ={
						"path": "/shop/"+shopId+"/info",
						"rename":"true",
					};
				this.setPostParams(options);
				//设定上传文件类型及说明
				var types = "*.jpg;*.gif;*.png";
				this.setFileTypes(types, "请选择");
				//设定上传文件体积,合法的单位有:B、KB、MB、GB，如果省略了单位，则默认为KB。该属性为0时，表示不限制文件的大小。
				this.setFileSizeLimit("2MB");
				this.startUpload();
			},
			upload_success_handler :function(file,data,response){
				var dataObj = eval('(' + data + ')');
				var dataPath="";
				if(dataObj.code == "1"){
					for(var i=0;i<dataObj.files.length;i++){
						if(dataObj.files[i].repCode=="1"){
							dataPath = dataObj.files[i].path;
							$("#iconUrl").attr("src", fileOpenUrl + dataPath);
							$("#iconUrlInput").val(dataPath);
						}else{
							alert("上传失败："+dataObj.files[i].repMsg);
						}
					}
				}else{
					alert("文件上传失败："+dataObj.msg);
				}
			},
			upload_complete_handler :function(file){
				this.startUpload();
			}
			
		}
	);
	
	$("#banner_upload_button").swfupload(CTX,
			{	
	        	button_width : 90,
	        	button_height : 20,
	        	button_text_left_padding : 20,
		        button_text_top_padding : 0.4,
		        button_text : "上传",
				upload_url : fileUploadUrl,
				progress_bar : $("#upload_progress ul"),
				file_dialog_complete_handler : function(countFile,countAddFile,countAllFile){
					//根据接口文档，定义所需 参数  
					var options ={
							"path": "/shop/"+shopId+"/info",
							"rename":"true",
						};
					this.setPostParams(options);
					//设定上传文件类型及说明
					var types = "*.jpg;*.gif;*.png";
					this.setFileTypes(types, "请选择");
					//设定上传文件体积,合法的单位有:B、KB、MB、GB，如果省略了单位，则默认为KB。该属性为0时，表示不限制文件的大小。
					this.setFileSizeLimit("2MB");
					this.startUpload();
				},
				upload_success_handler :function(file,data,response){
					var dataObj = eval('(' + data + ')');
					var dataPath="";
					if(dataObj.code == "1"){
						for(var i=0;i<dataObj.files.length;i++){
							if(dataObj.files[i].repCode=="1"){
								dataPath = dataObj.files[i].path;
								$("#bannerUrl").attr("src", fileOpenUrl + dataPath);
								$("#bannerUrlInput").val(dataPath);
							}else{
								alert("上传失败："+dataObj.files[i].repMsg);
							}
						}
					}else{
						alert("文件上传失败："+dataObj.msg);
					}
				},
				upload_complete_handler :function(file){
					this.startUpload();
				}
				
			}
		);
	
});
//查询二级分类
function findTypeForId(secId){
	$("#shopSecType [value!='']").remove();
	
	var parentId = $('#shopParType option:selected').val();
	jQuery.ajax({
			url: CTX+"/shop/Shop/findTypeForId.do",
			type:"POST",
			data:"parentId="+parentId,
			success:function(data){	
				for(var i in data){
					if(secId!=null&&data[i].shopTypeId == secId){
						$("#shopSecType").append('<option selected="selected" value="'+data[i].shopTypeId+'">'+data[i].shopTypeName+'</option>');
					}else{
						$("#shopSecType").append('<option value="'+data[i].shopTypeId+'">'+data[i].shopTypeName+'</option>');
					}
				}
					
			}
		});
}
